<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="bean.*" %>
<%@ page import="dao.*" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Iterator" %>
<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8" />
		<script type="text/javascript">
			function del() {
				if(!confirm("确认要删除该名学生相关信息？")) {
					window.event.returnValue = false;
				}
			}
		</script>
		<title>学生界面</title>
		<link type="text/css" rel="stylesheet" href="css/bootstrap.min.css">
		<link type="text/css" rel="stylesheet" href="css/index.css">
	<body>
		<%
			Customer c = (Customer) request.getSession().getAttribute("admin");
			//Teacher t = (Teacher)request.getSession().getAttribute("teacher");
			if(c == null){
				response.sendRedirect("Not_Login.jsp");
			}
		%>
		<div class="main">
			<div class="navigation">
				<span>欢迎回来! 
					<%
						if(c != null){
							out.print(c.getName());
						}
					%>
					管理员
				</span>
				<a class="exit" href="index.jsp"><span>退出登录</span></a>
			</div>
			<table class="table" style="margin:0 auto;width:90%">
				<tr>
					<td style="width:20%"><button class= "btn btn-info" style="width:100%" onclick="window.location.href='index_Admin.jsp'">公告</button></td>
					<td style="width:20%"><button class= "btn btn-info" style="width:100%" onclick="window.location.href='Manage_Students.jsp?pages=1'">学生管理</button></td>
					<td style="width:20%"><button class= "btn btn-info" style="width:100%" onclick="window.location.href='Manage_Teachers.jsp'">教师管理</button></td>
				</tr>
			</table>
			<div>
				<%
					ArrayList<Customer> list = AdminSql.GetStudent();
					Customer student = null;
				%>
				<table class="table table-hover; table_center"  style="margin:0 auto;width: 90%;color: white;font-weight: bolder">
					<tr>
						<th>学号</th>
						<th>姓名</th>
						<th>密码</th>
						<th>性别</th>
						<th><button class="btn btn-default btn-sm" onclick="window.location.href='Insert_Customer.jsp'">添加学生</button></th>
						<th>
							<form action="Select_Customer.jsp" method="post">
								<input type="text" name="check" placeholder="请输入查询ID或姓名" style="color: black"/>
								<button class="btn btn-default btn-sm" type="submit" name="submit" >搜索</button>
							</form>
						</th>
					</tr>
					<%
						if(list != null){
							Iterator<Customer> iterator = list.iterator();
							while(iterator.hasNext()){
								student = iterator.next();
					%>
					<tr>
						<td><%=student.getId() %></td>
						<td><%=student.getName() %></td>
						<td><%=student.getPassword() %></td>
						<td><%=student.getSex() %></td>
						<td><button class= "btn btn-default btn-sm" ><a href="Alter_Customer.jsp?ID=<%=student.getId() %>">修改</a></button></td>
						<td><button class= "btn btn-default btn-sm" onclick='javascript:return del();'><a href="RemoveServlet?ID=<%=student.getId() %>">删除</a></button></td>
					</tr>
					<%
							}
						}
					%>
				</table>
			</div>		
		</div>

	</body>
</html>
